package com.example.test1.controller;

import com.example.test1.model.MessageInfo;
import com.example.test1.service.MessageInfoServive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    MessageInfoServive messageInfoServive;
    @RequestMapping("/publish")
    public Boolean publish(MessageInfo messageInfo){
        System.out.println("接收到参数"+messageInfo);
        //参数检验
        if(!StringUtils.hasLength(messageInfo.getFrom())||!StringUtils.hasLength(messageInfo.getTo())||!StringUtils.hasLength(messageInfo.getMessage())){
            return false;
        }
        messageInfoServive.insert(messageInfo);
        return true;
    }
    @RequestMapping("/getlist")
    public List<MessageInfo> getList(){
        return messageInfoServive.selectAll();
    }
}
